package br.ufpr.inf.formulario.web;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import br.ufpr.inf.formulario.Aluno;
import br.ufpr.inf.formulario.Solicitacao;

@RooWebScaffold(path = "alunoes", formBackingObject = Aluno.class)
@RequestMapping("/alunoes")
@Controller
public class AlunoController {         @RequestMapping(method = RequestMethod.POST)
public String create(@Valid Aluno aluno, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("aluno", aluno);
        return "alunoes/create";
    }
    uiModel.asMap().clear();
    
    //
    Solicitacao solicitacao = new Solicitacao();
    solicitacao.setDataSolicitacao("");
    solicitacao.setParecer(false);
    solicitacao.persist();
    aluno.setSolicitacao( solicitacao);
    
    aluno.persist();
	uiModel.addAttribute("solicitacao", solicitacao);
	return "solicitacaos/update";
	

}  
}
